package com.webex.ta.hamal;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class HamalTester {

	private static void print(CommandResult r) {
		System.out.println(r.getStatuscode());
		System.out.println(r.getStatustext());
	}

	public static void main(String args[]) throws TException, IOException {
		TTransport tr = new TSocket("10.224.105.188", 9090);
		tr.open();
		TProtocol proto = new TBinaryProtocol(tr);
		Hamal.Client client = new Hamal.Client(proto);
		byte[] bytes = client.screenshot();
		
		File file = new File("./" + Calendar.getInstance().getTimeInMillis() + ".png");
		FileOutputStream fos = new FileOutputStream(file);
		fos.write(bytes);
		fos.close();
		
//		CommandResult r;
//		r = client.launchapp("AriesX");
//		print(r);
//		r = client.execute("activate", "AriesX", "");
//		client.execute("setvalue",
//				"windows['Aries X'].groups[1].text_fields[1]", "");
//		client.execute("setvalue",
//				"windows['Aries X'].groups[1].text_fields[3]", "");
//		client.execute("click", "windows['Aries X'].groups[1].text_fields[1]",
//				"");
//		client.execute("keystroke",
//				"windows['Aries X'].groups[1].text_fields[1]",
//				"vegaz@sz.webex.com");
//		client.execute("click", "windows['Aries X'].groups[1].text_fields[3]",
//				"");
//		client.execute("keystroke",
//				"windows['Aries X'].groups[1].text_fields[3]", "P@ssword123");
//		client.execute("click", "windows['Aries X'].buttons[2]", "");
//		r = client.execute("gettitle", "windows['Ride the Sheepony']", "");
//		print(r);
		// r = client.execute("rightclick",
		// "windows['Ride the Sheepony'].splitter_groups[1].scroll_areas[1].outlines[1].rows[3]",
		// "");
		// print(r);
	}

}

// TTransport tr = new TSocket("10.224.105.160", 9090);
// tr.open();
// TProtocol proto = new TBinaryProtocol(tr);
// Hamal.Client client = new Hamal.Client(proto);
// CommandResult r;
// r = client.launchapp("AriesX");
// print(r);
// r = client.execute("activate", "AriesX", "");
